package com.example.demo.leetcode.classics150;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _37矩阵置零
 * @description
 * @date 2023/07/20 14:24
 * <p>
 * ******************************************************
 */
public class _37矩阵置零 {

    public void setZeroes(int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;

        Set<Integer> row = new HashSet<>();
        Set<Integer> col = new HashSet<>();

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (0 == matrix[i][j]) {
                    row.add(i);
                    col.add(j);
                }
            }
        }

        for (Integer i : row) {
            Arrays.fill(matrix[i], 0);
        }

        for (Integer j : col) {
            for (int i = 0; i < m; i++) {
                matrix[i][j] = 0;
            }
        }

    }


    public static void main(String[] args) {
        _37矩阵置零 s = new _37矩阵置零();
        s.setZeroes(new int[][]{{0,1,2,0},{3,4,5,2},{1,3,1,5}});
    }
}
